package leetcode.tree;

public class Solution1 {

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        } else {
            int m = maxDepth(root.left);
            int n = maxDepth(root.right);
            return (m > n ? m : n) + 1;
        }
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(3);
        TreeNode root_left = new TreeNode(9);
        TreeNode root_right = new TreeNode(20);
        TreeNode root_right_left = new TreeNode(15);
        TreeNode root_right_right = new TreeNode(7);
        root.left = root_left;
        root.right = root_right;
        root_right.left = root_right_left;
        root_right.right = root_right_right;
        System.out.println(new Solution1().maxDepth(root));
    }
}